package logic

import (
	"context"
	"qimao-fiction/api/internal/svc"
	"qimao-fiction/api/internal/types"
	"qimao-fiction/qimaorpc/qimaorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type NovelUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewNovelUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NovelUpdateLogic {
	return &NovelUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *NovelUpdateLogic) NovelUpdate(req *types.NovelUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	update, err := l.svcCtx.QiMaoRpc.NovelUpdate(l.ctx, &qimaorpc.NovelUpdateRequest{
		Id:      req.Id,
		Title:   req.Title,
		Content: req.Content,
		Image:   req.Image,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	} else {
		return &types.Response{
			Message: "小说修改成功",
			Code:    200,
			Data:    update,
		}, nil
	}

}
